﻿using CoreModule;
using OxyPlot;
using OxyPlot.Annotations;
using OxyPlot.Axes;
using OxyPlot.Series;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace UIModule.ViewModels
{
    /// <summary>
    /// 分析界面 vm
    /// </summary>
    public class AnalysisViewModel : BindableBase,
        INavigationAware,
        IRegionMemberLifetime
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="notifier"></param>
        /// <param name="windowLifetime"></param>
        public AnalysisViewModel(INotifier notifier, IWindowLifetime windowLifetime)
        {
            windowLifetime.RegionViewKind = RegionViewKind.Analysis;
         
        }
         
        public bool KeepAlive => false;
          
        /// <summary>
        /// 测量累计 次数
        /// </summary>
        public int EntityTotalCount { get; set; } = CoreConstant.NotDevice;

        /// <summary>
        /// 达标 数量
        /// </summary>
        public int ComplianceCount { get; set; } = CoreConstant.NotDevice;

        /// <summary>
        /// 高血糖 次数
        /// </summary>

        public int HighCount { get; set; } = CoreConstant.NotDevice;

        /// <summary>
        /// 高血糖 百分比
        /// </summary>
        public double HighPercent { get; set; } = CoreConstant.NotDevice;

        /// <summary>
        /// 正常 次数
        /// </summary>
        public int NormalCount { get; set; } = CoreConstant.NotDevice;

        /// <summary>
        /// 正常 百分比
        /// </summary>
        public double NormalPercent { get; set; } =  CoreConstant.NotDevice;

        /// <summary>
        /// 低血糖 次数
        /// </summary>
        public int LowCount { get; set; } =   CoreConstant.NotDevice;

        /// <summary>
        /// 低血糖 百分比
        /// </summary>
        public double LowPercent { get; set; } = CoreConstant.NotDevice;

        /// <summary>
        /// 其他 数量
        /// </summary>
        public int OtherCount { get; set; }
         /// <summary>
        /// 其他 百分比
        /// </summary>
        public int OtherPercent { get; set; }


        public double MinValue { get; set; } = CoreConstant.NotDevice;
        public double AverageValue { get; set; } = CoreConstant.NotDevice;

        public double MaxValue { get; set; } = CoreConstant.NotDevice;

    
        /// <summary>
        /// 查询
        /// </summary>
        public ICommand QueryCommand => new Prism.Commands.DelegateCommand(Query);
        /// <summary>
        /// 重置
        /// </summary>
        public ICommand ResetCommand => new Prism.Commands.DelegateCommand(Reset);

        /// <summary>
        /// 随机 图表模型
        /// </summary>
        public PlotModel MainModel { get; set; }

        /// <summary>
        /// 重置 
        /// </summary>
        public void Reset()
        {
             
         
            this.SetQueryDay(QueryDay.Day7);
            Query();
        }
        /// <summary>
        /// 
        /// </summary>
        HandyControl.Controls.Pagination Pagination { get; set; }
   
        
        /// <summary>
        /// 查询
        /// </summary>
        public void Query()
        {
             
        }
         
        /// <summary>
        /// 选择的 前景色 颜色
        /// </summary>
        public Color CheckForegroundColor { get; set; } = Color.FromRgb(0XEB, 0X1C, 0X2A);

        /// <summary>
        /// 选择的 前景色 颜色
        /// </summary>
        public Color DefaultForegroundColor { get; set; } = Colors.Black;

        /// <summary>
        /// 选择的 背景色 
        /// </summary>
        public Color CheckBackgroundColor { get; set; } = Colors.Transparent;

        /// <summary>
        /// 默认的 背景色  F1F0F5
        /// </summary>
        public Color DefaultBackgroundColor { get; set; } = Color.FromRgb(0XF1, 0XF0, 0XF5);

        public ICommand Set7DaysCommand => new Prism.Commands.DelegateCommand(() => SetQueryDay( QueryDay.Day7));

        /// <summary>
        /// 未成年 #EB1C2A 
        /// </summary>
        public SolidColorBrush Set7DaysCommandBackground { get; set; } = new SolidColorBrush(Color.FromRgb(0XF1, 0XF0, 0XF5));

        /// <summary>
        /// 
        /// </summary>
        public SolidColorBrush Set7DaysCommandForeground { get; set; } = new SolidColorBrush(Colors.Black);
        /// <summary>
        /// 
        /// </summary>
        public Thickness Set7DaysCommandBorderThickness { get; set; } = new Thickness(0, 0, 0, 0);


        /// <summary>
        /// 
        /// </summary>
        public ICommand Set30DaysCommand => new Prism.Commands.DelegateCommand(() => SetQueryDay(QueryDay.Day30));

        /// <summary>
        /// 未成年 #EB1C2A 
        /// </summary>
        public SolidColorBrush Set30DaysCommandBackground { get; set; } = new SolidColorBrush(Color.FromRgb(0XF1, 0XF0, 0XF5));

        /// <summary>
        /// 
        /// </summary>
        public SolidColorBrush Set30DaysCommandForeground { get; set; } = new SolidColorBrush(Colors.Black);
        /// <summary>
        /// 
        /// </summary>
        public Thickness Set30DaysCommandBorderThickness { get; set; } = new Thickness(0, 0, 0, 0);
         
        public ICommand Set90DaysCommand => new Prism.Commands.DelegateCommand(() => SetQueryDay(QueryDay.Day90));

        /// <summary>
        /// 未成年 #EB1C2A 
        /// </summary>
        public SolidColorBrush Set90DaysCommandBackground { get; set; } = new SolidColorBrush(Color.FromRgb(0XF1, 0XF0, 0XF5));

        /// <summary>
        /// 
        /// </summary>
        public SolidColorBrush Set90DaysCommandForeground { get; set; } = new SolidColorBrush(Colors.Black);
        /// <summary>
        /// 
        /// </summary>
        public Thickness Set90DaysCommandBorderThickness { get; set; } = new Thickness(0, 0, 0, 0);


        /// <summary>
        /// 
        /// </summary>
        /// <param name="BloodGlucoseStatus"></param>
        public void SetQueryDay(QueryDay  queryDay)
        {

            this.Set7DaysCommandBackground = (queryDay ==  QueryDay.Day7)
             ? new SolidColorBrush(CheckBackgroundColor)
             : new SolidColorBrush(DefaultBackgroundColor);

            this.Set7DaysCommandForeground = (queryDay == QueryDay.Day7)
                 ? new SolidColorBrush(CheckForegroundColor)
                : new SolidColorBrush(DefaultForegroundColor);
            this.Set7DaysCommandBorderThickness = (queryDay == QueryDay.Day7)
                 ? new Thickness(1, 1, 1, 1)

                : new Thickness(0, 0, 0, 0);

            this.Set30DaysCommandBackground = (queryDay == QueryDay.Day30)
         ? new SolidColorBrush(CheckBackgroundColor)
         : new SolidColorBrush(DefaultBackgroundColor);

            this.Set30DaysCommandForeground = (queryDay == QueryDay.Day30)
                 ? new SolidColorBrush(CheckForegroundColor)
                : new SolidColorBrush(DefaultForegroundColor);
            this.Set30DaysCommandBorderThickness = (queryDay == QueryDay.Day30)
                 ? new Thickness(1, 1, 1, 1)
                : new Thickness(0, 0, 0, 0);


            this.Set90DaysCommandBackground = (queryDay == QueryDay.Day90)
            ? new SolidColorBrush(CheckBackgroundColor)
             : new SolidColorBrush(DefaultBackgroundColor);

            this.Set90DaysCommandForeground = (queryDay == QueryDay.Day90)
                ? new SolidColorBrush(CheckForegroundColor)
                : new SolidColorBrush(DefaultForegroundColor);
            this.Set90DaysCommandBorderThickness = (queryDay == QueryDay.Day90)
                 ? new Thickness(1, 1, 1, 1)
                : new Thickness(0, 0, 0, 0);


           
            this.RaisePropertyChanged(nameof(Set7DaysCommandBackground));
            this.RaisePropertyChanged(nameof(Set7DaysCommandForeground));
            this.RaisePropertyChanged(nameof(Set7DaysCommandBorderThickness));
            ///
            this.RaisePropertyChanged(nameof(Set30DaysCommandBackground));
            this.RaisePropertyChanged(nameof(Set30DaysCommandForeground));
            this.RaisePropertyChanged(nameof(Set30DaysCommandBorderThickness));
            ///
            this.RaisePropertyChanged(nameof(Set90DaysCommandBackground));
            this.RaisePropertyChanged(nameof(Set90DaysCommandForeground));
            this.RaisePropertyChanged(nameof(Set90DaysCommandBorderThickness));

             var baseTime=Extension.GetBaseDateTime(queryDay);
             
            this.BloodGlucoseMeasurementInfos = this.BluetoothDataPickerResult.BloodGlucoseMeasurementInfos
                .Where(item => item.MeasurementTime >= baseTime)
            .ToList();
            this.CleanSummaryProperty();
            this.Compute();
            this.RaiseSummaryPropertyChanged();
            this.UpdateModel(queryDay );
             
        }


        /// <summary>
        /// 测试数据
        /// </summary>
        private List<BloodGlucoseMeasurementInfo> BloodGlucoseMeasurementInfos { get; set; } = new List<BloodGlucoseMeasurementInfo>();

        /// <summary>
        /// 区域管理器 没有使用
        /// </summary>

        IRegionManager RegionManager { get; set; }
    
        /// <summary>
        /// 蓝牙查询结果
        /// </summary>
        public BluetoothQueryResult BluetoothQueryResult { get; set; }


        /// <summary>
        /// 蓝牙查询结果
        /// </summary>

        BluetoothDataPickerResult BluetoothDataPickerResult { get; set; } = new BluetoothDataPickerResult();

     
        /// <summary>
        /// 计算 统计数据
        /// </summary>
        public void Compute()
        {
            
            ///
            if (BluetoothQueryResult == BluetoothQueryResult.NotDevice)
            {
                EntityTotalCount = CoreConstant.NotDevice;
                ComplianceCount = CoreConstant.NotDevice;
                HighCount = CoreConstant.NotDevice;
                HighPercent = CoreConstant.NotDevice;
                LowCount = CoreConstant.NotDevice;
                LowPercent = 0;
                NormalCount = CoreConstant.NotDevice;
                NormalPercent = 0;
                OtherCount = CoreConstant.NotDevice;
                OtherPercent = 0;
            
              
                return;
            }

            if (BloodGlucoseMeasurementInfos.Count == 0)
            {
                EntityTotalCount = 0;
                ComplianceCount = 0;
                HighCount = 0;
                HighPercent = 0;
                LowCount = 0;
                LowPercent = 0;
                NormalCount = 0;
                NormalPercent = 0;
                OtherCount = 0;
                OtherPercent = 0;

               
                return;
            }

            EntityTotalCount = this.BloodGlucoseMeasurementInfos.Count;

            ComplianceCount = this.BloodGlucoseMeasurementInfos
                .Count(item => item.BloodGlucoseStatus == BloodGlucoseStatus.Normal);

            HighCount = this.BloodGlucoseMeasurementInfos.Count(item => item.BloodGlucoseStatus == BloodGlucoseStatus.High);

            HighPercent = HighCount * 100 / EntityTotalCount;


            LowCount = this.BloodGlucoseMeasurementInfos.Count(item => item.BloodGlucoseStatus == BloodGlucoseStatus.Low);

            LowPercent = LowCount * 100 / EntityTotalCount;

            NormalCount = this.BloodGlucoseMeasurementInfos.Count(item => item.BloodGlucoseStatus == BloodGlucoseStatus.Normal);

            NormalPercent = NormalCount * 100 / EntityTotalCount;

            OtherCount = this.BloodGlucoseMeasurementInfos.Count(item => item.BloodGlucoseStatus == BloodGlucoseStatus.HI
            || item.BloodGlucoseStatus == BloodGlucoseStatus.LO);

           

            ///
            if (BloodGlucoseMeasurementInfos
              .Any(item=>!item.IsUnusual))
            {
                MinValue = this.BloodGlucoseMeasurementInfos
                                 .Where(item=>!item.IsUnusual)
                                 .Min(item => item.MeasurementValue);

                AverageValue = this.BloodGlucoseMeasurementInfos
                    .Where(item => !item.IsUnusual)
                                  .Average(item => item.MeasurementValue);

                MaxValue = this.BloodGlucoseMeasurementInfos
                                .Where(item => !item.IsUnusual)
                                 .Max(item => item.MeasurementValue);
            }
        }

        /// <summary>
        /// 导航
        /// </summary>
        /// <param name="navigationContext"></param>
        public void OnNavigatedTo(NavigationContext navigationContext)
        {

            this.CleanSummaryProperty();
            BluetoothDataPickerResult = navigationContext.Parameters[CoreConstant.BluetoothDataPickerResultKey] as CoreModule.BluetoothDataPickerResult;

            //BluetoothDataPickerResult.BluetoothQueryResult = BluetoothQueryResult.HasDate;
            BluetoothQueryResult = BluetoothDataPickerResult.BluetoothQueryResult;

            var baseTime =Extension.GetBaseDateTime(QueryDay.Day90);

            this.BloodGlucoseMeasurementInfos = BluetoothDataPickerResult
                .BloodGlucoseMeasurementInfos.Where(item => item.MeasurementTime >= baseTime).ToList();
 

            if (BluetoothDataPickerResult.BluetoothQueryResult == BluetoothQueryResult.NotDevice)
            {
                this.EntityTotalCount = CoreConstant.NotDevice;

                this.HighCount = CoreConstant.NotDevice;
                this.HighPercent = 0;

                this.LowCount = CoreConstant.NotDevice;
                this.NormalPercent = 0;

                this.NormalCount = CoreConstant.NotDevice;
                this.NormalPercent = 0;
                ///
                this.OtherCount = CoreConstant.NotDevice;
                this.OtherPercent =0;
                 
            }
          
            ///
            else if (BluetoothDataPickerResult.BluetoothQueryResult == BluetoothQueryResult.HasDate)
            {

              
                this.Compute();

            }
            this.Compute();

            
            RaiseSummaryPropertyChanged();

            this.Reset();
            this.UpdateModel( QueryDay.Day7);
            

        }

        /// <summary>
        /// 清除统计值
        /// </summary>
        public void CleanSummaryProperty()
        {

            EntityTotalCount = CoreConstant.NotDevice;
            ComplianceCount = CoreConstant.NotDevice;

            HighCount = CoreConstant.NotDevice;
            HighPercent = 0;

            HighCount = CoreConstant.NotDevice;
            HighPercent = 0;

            LowCount = CoreConstant.NotDevice;
            LowPercent = 0;

            NormalCount = CoreConstant.NotDevice;
            NormalPercent = 0;


            OtherCount = CoreConstant.NotDevice;
            OtherPercent = 0;


            MinValue= CoreConstant.NotDevice;
            AverageValue = CoreConstant.NotDevice;
            MaxValue = CoreConstant.NotDevice;


        }

        /// <summary>
        /// 统计值 更新到界面
        /// </summary>
        public void RaiseSummaryPropertyChanged()
        {

            this.RaisePropertyChanged(nameof(EntityTotalCount));
            this.RaisePropertyChanged(nameof(ComplianceCount));

            this.RaisePropertyChanged(nameof(HighCount));
            this.RaisePropertyChanged(nameof(HighPercent));


            this.RaisePropertyChanged(nameof(NormalCount));
            this.RaisePropertyChanged(nameof(NormalPercent));

            this.RaisePropertyChanged(nameof(LowCount));
            this.RaisePropertyChanged(nameof(LowPercent));
            
            this.RaisePropertyChanged(nameof(OtherCount));
            this.RaisePropertyChanged(nameof(OtherPercent));

           

            this.RaisePropertyChanged(nameof(MinValue));
            this.RaisePropertyChanged(nameof(AverageValue));
            this.RaisePropertyChanged(nameof(MaxValue));

        }



        /// <summary>
        /// 更新模式
        /// </summary>
        public void UpdateModel(QueryDay queryDay)
        {
            var maxY = this.BloodGlucoseMeasurementInfos.Count > 0 ? this.BloodGlucoseMeasurementInfos
              .Max(item => item.MeasurementValue) : 35.0;

            List<double> textPositions = new List<double>() { 0, 10, 20, 30 };
            double yAbsoluteMinimum = -3;
            double yAbsoluteMaximum = 37;
            double bottomLineIntercept = -2;
            double topLineIntercept = 35;
           if (maxY > 30)
            {
                 textPositions = new List<double>() { 0, 10, 20, 30 };
                 yAbsoluteMinimum = -3;
                 yAbsoluteMaximum = 37;
                 bottomLineIntercept = -2;
                 topLineIntercept = 36;
            }
            else if (maxY>25)
            {
                textPositions = new List<double>() { 0, 10, 20, 30 };
                yAbsoluteMinimum = -3;
                yAbsoluteMaximum = 34;
                bottomLineIntercept = -2;
                topLineIntercept = 32;

            }
            else if (maxY > 20)
            {
                  textPositions = new List<double>() { 0, 5, 10, 15,20 };
                 yAbsoluteMinimum = -3;
                 yAbsoluteMaximum = 24;
                 bottomLineIntercept = -2;
                 topLineIntercept = 23;
            } else if (maxY > 15)
            {
                textPositions = new List<double>() { 0, 5, 10, 15 };
                yAbsoluteMinimum = -3;
                yAbsoluteMaximum = 22;
                bottomLineIntercept = -2;
                topLineIntercept = 21;
            }
            else
            {
                textPositions = new List<double>() { 0, 5, 10, 15 };
                yAbsoluteMinimum = -3;
                yAbsoluteMaximum = 22;
                bottomLineIntercept = -2;
                topLineIntercept = 21;
            }

           
            this.MainModel = this.CreateRandomModel(queryDay, textPositions,yAbsoluteMinimum,yAbsoluteMaximum , bottomLineIntercept,topLineIntercept);
              
           
            this.RaisePropertyChanged(nameof(MainModel));
          
        }


        /// <summary>
        /// 没有使用
        /// </summary>
        /// <param name="navigationContext"></param>
        /// <returns></returns>
        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return false;
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="navigationContext"></param>
        public void OnNavigatedFrom(NavigationContext navigationContext)
        {

        }
        /// <summary>
        /// 创建 饭前、饭后、随机通用模型
        /// </summary>
        /// <param name="queryDay"></param>
        /// <returns></returns>
        public PlotModel CreateEmptyModel(QueryDay queryDay
                        ,double rectangleAnnotationMinY
                        ,double rectangleAnnotationMaxY
                        ,List<double> textPositions
                        ,double yAbsoluteMinimum=-3
                        ,double yAbsoluteMaximum=37
                        ,double bottomLineIntercept=-2
                        ,double topLineIntercept=35
            )
        {
            var now = DateTime.Now;

            var min = now.AddDays(1-7);

            if (queryDay== QueryDay.Day30)
            {
               min = now.AddDays(1-30);
            }
            if (queryDay == QueryDay.Day90)
            {
               min = now.AddDays(1-90);
            }

            var minTime = new DateTime(min.Year, min.Month, min.Day, 0, 0, 0);
            var max = now;

            var maxTime = max;

            var totalDay = maxTime.Subtract(minTime).TotalDays;
             

            var leftLineTime = minTime.AddDays(0 - totalDay * 0.05);

            var rightLineTime = maxTime.AddDays(totalDay * 0.05);

            var leftTextTime = minTime.AddDays(0 - totalDay * 0.025);

           var  xMinTime = minTime.AddDays(0 - totalDay * 0.0);

           var  xMaxTime = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59);

            var plotModel = new PlotModel();
            plotModel.PlotAreaBorderColor = OxyColors.Transparent;

            plotModel.Title = "";
            plotModel.TitleFontSize = 0;
            plotModel.TitleHorizontalAlignment = TitleHorizontalAlignment.CenteredWithinView;

            var rectangleAnnotation = new RectangleAnnotation();

            rectangleAnnotation.Layer = AnnotationLayer.BelowSeries;
            rectangleAnnotation.MinimumX = DateTimeAxis.ToDouble(xMinTime);
            rectangleAnnotation.MaximumX = DateTimeAxis.ToDouble(xMaxTime);

            rectangleAnnotation.MinimumY = rectangleAnnotationMinY;
            rectangleAnnotation.MaximumY = rectangleAnnotationMaxY;
            rectangleAnnotation.Fill = Extension.GetRectangleAnnotationOxyColor();
            rectangleAnnotation.StrokeThickness = 0;
            rectangleAnnotation.Text = "";
            rectangleAnnotation.TextRotation = 0;
            plotModel.Annotations.Add(rectangleAnnotation);


            var bottomAxis = new DateTimeAxis();
            bottomAxis.Minimum = DateTimeAxis.ToDouble(xMinTime);
            bottomAxis.Maximum = DateTimeAxis.ToDouble(xMaxTime);


            
            bottomAxis.IntervalType = DateTimeIntervalType.Days;
            bottomAxis.MinorIntervalType = DateTimeIntervalType.Hours;

            if (totalDay < 10)
            {
                bottomAxis.IntervalLength = 120;
            }
             
             //bottomAxis.StringFormat = "MM-dd";


            List<string> lables = new List<string>();


            bottomAxis.LabelFormatter = value =>
            {

                var d = DateTimeAxis.ToDateTime(value);
                if (d < xMinTime)
                {
                    return string.Empty;
                }
                else if (d > xMaxTime)
                {
                    return string.Empty;
                }
                else
                {

                    var lable = DateTimeAxis.ToDateTime(value).ToString("MM-dd");

                    return lable;
                }
            };

            bottomAxis.AbsoluteMaximum = DateTimeAxis.ToDouble(xMaxTime);
            bottomAxis.AbsoluteMinimum = DateTimeAxis.ToDouble(xMinTime);

            bottomAxis.IsAxisVisible = true;
            bottomAxis.IsZoomEnabled = false;

            bottomAxis.Position = AxisPosition.Bottom;
            bottomAxis.AxislineColor = OxyColors.Red;

            bottomAxis.TickStyle = TickStyle.None;
            bottomAxis.IsZoomEnabled = false;

            bottomAxis.AxislineStyle = LineStyle.None;
            bottomAxis.MaximumPadding = 0.05;
            bottomAxis.MinimumPadding = 0.05;

            plotModel.Axes.Add(bottomAxis);
            var leftAxis = new LinearAxis();
            leftAxis.AbsoluteMaximum = yAbsoluteMaximum;
            leftAxis.AbsoluteMinimum = yAbsoluteMinimum;
            leftAxis.Maximum = yAbsoluteMaximum;
            leftAxis.Minimum = yAbsoluteMinimum;
            
            leftAxis.IsAxisVisible = true;
            leftAxis.IsZoomEnabled = false;

            var mavY = textPositions.Max();

            leftAxis.LabelFormatter = value => { 
                
                if (value >= topLineIntercept)
                {
                    return string.Empty;
                }
                else if(value<0)
                    {
                    return string.Empty;
                } 
                
                return value.ToString(); };

            leftAxis.Position = AxisPosition.Left;
            leftAxis.TickStyle = TickStyle.None;
            plotModel.Axes.Add(leftAxis);

           

            var bottomLine = new LineAnnotation();
            bottomLine.Intercept = bottomLineIntercept;
            bottomLine.Slope = 0;
            bottomLine.LineStyle = LineStyle.Solid;
            bottomLine.Color = Extension.GetLimitLineOxyColor();
            bottomLine.MinimumX = DateTimeAxis.ToDouble(xMinTime);
            bottomLine.MaximumX = DateTimeAxis.ToDouble(xMaxTime); ;

            bottomLine.Text = "";
            plotModel.Annotations.Add(bottomLine);

            var topLine = new LineAnnotation();
            topLine.Intercept = topLineIntercept;
            topLine.Slope = 0;
            topLine.LineStyle = LineStyle.Solid;
            topLine.Color = Extension.GetLimitLineOxyColor();

            topLine.MinimumX = DateTimeAxis.ToDouble(xMinTime);
            topLine.MaximumX = DateTimeAxis.ToDouble(xMaxTime); ;

            topLine.Text = "";
            plotModel.Annotations.Add(topLine);

            return plotModel;
        }


        /// <summary>
        /// 添加数据到模型
        /// </summary>
        /// <param name="bloodGlucoseMeasurementInfos"></param>
        public PlotModel AddDataToPlotModel(PlotModel plotModel, List<BloodGlucoseMeasurementInfo> bloodGlucoseMeasurementInfos)
        {
            var lineSeries1 = new LineSeries();

            lineSeries1.BrokenLineThickness = 0.5;

            lineSeries1.StrokeThickness = Extension.GetLineSeriesStrokeThickness();

            foreach (var bloodGlucoseMeasurementInfo in bloodGlucoseMeasurementInfos)
            {
                var point = DateTimeAxis.CreateDataPoint(bloodGlucoseMeasurementInfo.MeasurementTime, bloodGlucoseMeasurementInfo.MeasurementValue);

                lineSeries1.Points.Add(point);

                var centerPoint = new PointAnnotation();
                centerPoint.Fill = Extension.GetBloodGlucoseStatusOxyColor(bloodGlucoseMeasurementInfo.BloodGlucoseStatus);
                centerPoint.X = point.X;
                centerPoint.Y = point.Y;
                centerPoint.Size = Extension.GetPointAnnotationSize(); ;
                centerPoint.Text = "";
                centerPoint.TextHorizontalAlignment = OxyPlot.HorizontalAlignment.Left;
                centerPoint.TextVerticalAlignment = OxyPlot.VerticalAlignment.Middle;
                plotModel.Annotations.Add(centerPoint);

            }

            lineSeries1.Color = Extension.GetLineSeriesColor();

            lineSeries1.CanTrackerInterpolatePoints = false;

            plotModel.Series.Add(lineSeries1);
            return plotModel;

        }

         
       
        /// <summary>
        ///  随机 模型
        /// </summary>
        /// <returns></returns>

        public PlotModel CreateRandomModel(QueryDay queryDay
            , List<double> textPositions
            , double yAbsoluteMinimum = -3
            , double yAbsoluteMaximum = 37
            , double bottomLineIntercept = -2
            , double topLineIntercept = 35)
        {
            var items = BloodGlucoseMeasurementInfos;
               
            var plotModel = CreateEmptyModel(queryDay
              , CoreConstant.MinNormalValue
              , CoreConstant.MinHighValue
              , textPositions
              , yAbsoluteMinimum, yAbsoluteMaximum, bottomLineIntercept, topLineIntercept);


            if (items.Count == 0)
            {
                return plotModel;
            }
            else
            {
                return AddDataToPlotModel(plotModel, items);
            }

        }

     
          
    }
}
